<?php


namespace App\Listener;

use App\Event\UserCreated;
use Hyperf\Event\Contract\ListenerInterface;


/**
 * 用户创建成功事件侦听器
 * 作者 薛原
 * 用于执行用户注册后续操作，如补全资料表
 * Class UserCreatedListener
 * @package App\Listener
 */
class UserCreatedListener implements ListenerInterface
{
    private \App\Service\UserProfilesService $userProfilesService;

    public function __construct(\App\Service\UserProfilesService $userProfilesService) {
        // 依赖注入容器配置
        $this->userProfilesService = $userProfilesService;
    }
    public function listen(): array {
        return [UserCreated::class];
    }
    public function process(object $event): void {
        // 处理事件
        //此处补全生成 user_profiles 表数据
        $data = [];
        $data['user_id'] = $event->user_data['id'];
        $this->userProfilesService->initUserProfiles($data);
    }
}